<?php

/**
 * Created by PhpStorm.
 * User: zhengze
 * Date: 2019/7/1
 * Time: 18:29
 */

namespace app\admin\logic;


use app\common\model\AdminPost;
use app\common\logic\BaseLogic;
use app\common\traits\InstanceTrait;

/**
 * Class PostLogic
 * @package app\admin\logic
 * @property AdminPost $model
 */
class PostLogic extends BaseLogic
{
    use InstanceTrait;

    public function __construct($model = null)
    {
        $this->model = AdminPost::instance();
        parent::__construct($model);
    }

    /**
     * 获取列表
     * @param $param
     * @return mixed|\think\Model|\think\model\Pivot|null
     */
    public function getList($param)
    {
        $AdminPost = AdminPost::instance();
        $data = $AdminPost->getList($param);
        $data->load('admins')->visible(['admins.admin_id']);
        return $data;
    }

    public function getCount($param)
    {
        $data = $this->model->getCount($param);
        return $data;
    }

    public function getByID($param)
    {
        $data = $this->model->getByID($param[$this->model->getPk()] ?? $param['id']);
        return $data;
    }

    public function createData($param)
    {
        $data = $this->model->createData($param);
        return $data;
    }

    public function updateByID($param)
    {
        $data = $this->model->updateByID($param, $param[$this->model->getPk()] ?? $param['id']);
        return $data;
    }

    public function delByID($param)
    {
        $data = $this->model->delByID($param[$this->model->getPk()] ?? $param['id'], false);
        return $data;
    }

    public function delByIDs($param)
    {
        $data = $this->model->delByIDs($param[$this->model->getPk().'s'] ??$param['ids'], false);
        return $data;
    }

    public function enableByIDs($param)
    {
        $data = $this->model->enableByIDs($param[$this->model->getPk().'s'] ??$param['ids'], $param['status'], false);
        return $data;
    }
}
